package com.tg.paw.ums.controller;

import com.tg.paw.common.component.UserUtil;
import com.tg.paw.common.util.CommonResult;
import com.tg.paw.ums.entity.Admin;
import com.tg.paw.ums.model.WxUserInfo;
import com.tg.paw.ums.service.IAdminService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Rubble
 * @date 2020/6/24
 */
@RestController
@RequestMapping("/wx/store")
public class WxStoreAdminController {

    @Autowired
    private IAdminService adminService;

    @ApiOperation("微信更新用户信息")
    @PostMapping("/userInfo")
    public CommonResult updateUserInfo(@RequestBody WxUserInfo userInfo){
        String openId = UserUtil.getLoginUser().getUserName();
        Admin admin = adminService.getByOpenId(openId);
        Admin record = new Admin();
        record.setAdminId(admin.getAdminId());
        record.setCountry(userInfo.getCountry());
        record.setGender(userInfo.getGender());
        record.setProvince(userInfo.getProvince());
        record.setAvatar(userInfo.getAvatarUrl());
        record.setCity(userInfo.getCity());
        record.setNickName(userInfo.getNickName());
        adminService.save(record);

        return CommonResult.success();
    }
}
